#ifndef COMMON_H
#define COMMON_H

#include <assert.h>
#include <math.h>
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <ctype.h>
#include <limits.h>

#include <SDL/SDL.h>
#include "keymap.h"

typedef enum {
	false,
	true
} bool;

typedef SDL_Color	color_t;
typedef SDL_Rect	rect_t;

typedef struct {
	int x;
	int y;
	int z;
} vetex_t;

typedef float vec2_t[2];
typedef float vec3_t[3];
typedef float vec4_t[4];
typedef float vec5_t[5];

typedef unsigned char		byte;
typedef unsigned int		uint32;
typedef unsigned long long	uint64;

#ifdef PATH_MAX
#define MAX_OSPATH			PATH_MAX
#else
#define	MAX_OSPATH			256
#endif

void com_quit(int error);

//异常或事件记录
void com_error(const char * msg);
void com_warning(const char * msg);
void com_fatal(const char * msg);
void com_log(const char * msg);


//事件队列
typedef struct {
	enum {
		EV_NONE = 0,
		EV_KEY,
		EV_MOUSE_POS,
		EV_MOUSE_REL
	} type;
	union {
		struct {	//EV_KEY
			int key;
			bool down;
		};
		struct {	//EV_MOUSE
			int x;
			int y;
		};
	};
	uint32 time;
} event_t;

keynum_t	com_translate_key(SDL_keysym * keysym);
void		com_queue_event(int type, int value1, int value2);
event_t *	com_get_event(void);

//内存操作
void *	com_malloc(size_t size);
char *	com_strdup(const char * str);
void	com_free(void * mem_ptr);
#define com_memset memset
#define com_memcpy memcpy

//十六进制字符串转整数
int		com_hexstr_to_int(const char * str);

//命令
void	cmd_buf_add(const char * cmd);
void	cmd_exec_buf(void);
void	cmd_exec_file(const char * filename);

#endif /* end of include guard: COMMON_H */
